import {
    GETDATA,
    J,
    getField
} from '../utils/R'

export default {
    namespace: 'centerTop',
    state: {},
    subscriptions: {
        setup({
            dispatch,
            history
        }) {
            history.listen(({
                pathname
            }) => {
                if (pathname == '/two') {
                    dispatch({
                        type: 'getDatas'
                    })
                }
            })
        }
    },
    effects: {
        * getDatas({
            params
        }, {
            call,
            put
        }) {

            let {
                data
            } = yield call(GETDATA, J, {}, {
                zq: "201"
            })
            let payload = {
                dataArr: getField(data, 'sums'),
                lisrArr: getField(data, 'score')
            }

            yield put({
                type: 'setData',
                payload
            })
        }
    },
    reducers: {
        setData(state, action) {
            return action.payload
        }
    }
}